<?php

declare(strict_types=1);

namespace Plugin\Attractions\Commerce\Model\Commerce_commodity;

use Hyperf\DbConnection\Model\Model;
use Plugin\Attractions\Commerce\Model\Commerce_commodity_type\CommerceCommodityType;
use Plugin\Attractions\Commerce\Model\Commerce_merchant\CommerceMerchant;

/**
 * @property int $id 主键ID
 * @property int $merchant_id 商户ID
 * @property string $commodity_name 商品名称
 * @property int $commodity_category 商品分类
 * @property string $commodity_brand 商品品牌
 * @property string $commodity_model 商品型号
 * @property array $commodity_spec 商品规格
 * @property string $commodity_unit 计量单位
 * @property string $commodity_description 商品描述
 * @property string $sale_price 销售价
 * @property string $discount 折扣
 * @property string $full_amount 满减满足金额
 * @property string $full_reduction 满减扣除金额
 * @property int $stock_quantity 库存数量
 * @property int $sales_quantity 销量
 * @property array $commodity_images 商品图片（JSON格式）
 * @property int $status 商品状态：1-上架，2-下架
 * @property int $sort_order 排序
 * @property string $remark 备注
 * @property \Carbon\Carbon $created_at 
 * @property \Carbon\Carbon $updated_at 
 */
class CommerceCommodity extends Model
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'commerce_commodity';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'merchant_id', 'commodity_name', 'commodity_category', 'commodity_brand', 'commodity_model', 'commodity_spec', 'commodity_unit', 'commodity_description', 'sale_price', 'discount', 'full_amount', 'full_reduction', 'stock_quantity', 'sales_quantity', 'commodity_images', 'status', 'sort_order', 'remark', 'created_at', 'updated_at'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'merchant_id' => 'integer', 'commodity_category' => 'integer', 'commodity_spec' => 'array', 'sale_price' => 'decimal:2', 'discount' => 'decimal:2', 'full_amount' => 'decimal:2', 'full_reduction' => 'decimal:2', 'stock_quantity' => 'integer', 'sales_quantity' => 'integer', 'commodity_images' => 'array', 'status' => 'integer', 'sort_order' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];

    public function type()
    {
        return $this->hasOne(CommerceCommodityType::class, 'id', 'commodity_category');
    }
    
    public function merchant()
    {
        return $this->hasOne(CommerceMerchant::class, 'id', 'merchant_id');
    }
}
